Dynamic Programming
Friday, June 26, 2015
9:37 AM
<<dynamic-programming.pdf>>
Inserted from: <file://\\psf\Dropbox\Schoolworks\Waterloo Terms\4B\CS431 Algo\dynamic-programming.pdf>










![Machine generated alternative text: •-a.—-r.—_ Cam
Coin Changing
Problem
Coin Changing
Instance: A ¡Est of coin denominations. 1 = .4. and a
pzsitive ¡nte jet T, which is called the target sum.
Find: An n-tuple of non-negative integers, say.4 = ,..-, a,. such
that T = ED-: a,d, an. such that ‘ = a is minimized.
Let Nì.t] denote the optimal solution to the subproblem consisting of the
fir. i coin denominations D:. . .p and :aget sum t. Le: A.t denote
te n_mber of coins o cenomva:ion d _sed n the optimal solution to
this subp’oblem.
.7 S- Was, 5 UI? 22?
•a’_z___ Cam cta,$qg
A Dynamic Programming Algorithm for Coin
Changing
Algorithm: Coin Changing(da... - ¿n. T)
comment: d. = 1
for t , 0 to T
1_,v.1.t] — t
do <14•i:t t
for — 2 to n
(for t — C’ to T
—
I4:i.t:—0
do d forj—lto
fj--Xi—1.t—jdJcX’z.tJ
: I do then
j t t
return
S «s. - WflitS., 5Z2 225 .127](index_files/image011.png)

![Machine generated alternative text: •3a_.P_fl L_ga Can.... S.S....
Finding the LCS of X and Y
Algorithm: LCS2(X = (x ,...,x,j.Y =
for t.— O to ni do ci,O] .— 0
for j —0 to n do c[o,j: o
for t — 1 to ni
(for j — 1 to
then
do d else if ci.j—ij > c:t— 1d
then {ciM —ci,j—f
Ici. ( — cl — 1.j
I. 1ee w:;:—a
return (c. r);
! • —‘——:&i ! tintas. 20L! ::3 ir
Lela Ca,.,,.r Staa’z.
Finding the LCS
Algorithm: F1ndLCS(c, r, t)
— ()
i—ni
j—n
while mizi{i.j} > 0
(if ir[t.j] =UL
I (seq—zn seQ
then ¿t—t—l
do I. . .
ti) -
lelse if rï,f =L thenj—j—1
lelse 1— t—1
return (seq)
taitas, 5ZS 124 .‘ 12?](index_files/image013.png)


Created with Microsoft OneNote 2010
One place for all your notes and information